package cn.com.product.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.com.product.bean.Product;
import cn.com.product.bean.ProductBean;

/**
 * Servlet implementation class ProductAddServlet
 */
public class ProductAddServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ProductAddServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String id = request.getParameter("id");
		String category = request.getParameter("category");
		String name = request.getParameter("name");
		String producer = request.getParameter("producer");
		String price = request.getParameter("price");
		String descn = request.getParameter("descn");
		Product p = new Product();
		p.setProductid(id);
		p.setCategory(category);
		p.setName(name);
		p.setProducer(producer);
		p.setPrice(Double.valueOf(price));
		p.setDescn(descn);
		ProductBean pb = new ProductBean();
		pb.addProduct(p);
		List<Product> list = new ArrayList<Product>();
		list = pb.getProducts();
		request.setAttribute("listproduct", list);
		request.getRequestDispatcher("/checkProduct.jsp").forward(request, response);
	}

}
